import { observable, action, autorun,toJS } from 'mobx';
import {WeaTableNew,WeaForm} from 'comsMobx'
import {message,Modal} from 'antd';
const {TableStore} = WeaTableNew;
import {WeaLocaleProvider} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
import { ListStore } from './listStore';
import {WeaTools} from "ecCom"
import * as  Apis from '../apis/project';
import {ShareStore} from './shareStore'

class BatchShareStore  extends ListStore{	
   	@observable rightMenu =[];
	conditiontype = {conditiontype:"batchshare"};
	@observable showLeft = true;
	 /** 左侧树store */
	 @observable  leftTree = [];
	 @observable leftTreeCount = {};
	 @observable leftTreeCountType = [];
     @observable selectedTreeKey = "";
     
     @observable shareStore = new ShareStore();
     @observable visible= false;
     shareCondition =  [
		{
			"colSpan": 2,
			"conditionType": "SELECT",
			"domkey": [
				"sharetype"
			],
			"fieldcol": 16,
			"isQuickSearch": false,
			"label": getLabel(21956,"对象类型"),
			"labelcol": 6,
			"options": [
				{
					"key": "1",
					"selected": true,
					"showname": getLabel(179,"人力资源")
				}, {
					"key": "5",
					"selected": false,
					"showname": getLabel(141,"分部")
				}, {
					"key": "2",
					"selected": false,
					"showname": getLabel(124,"部门")
				}, {
					"key": "11",
					"selected": false,
					"showname": getLabel(6086,"岗位")
				}, {
					"key": "3",
					"selected": false,
					"showname": getLabel(122,"角色")
				}, {
					"key": "4",
					"selected": false,
					"showname": getLabel(1340,"所有人")
				}
			],
			"viewAttr": 2
		}, {
			"2": [[
					{
						"browserConditionParam": {
							"completeParams": {},
							"conditionDataParams": {},
							"dataParams": {},
							"destDataParams": {},
							"hasAddBtn": false,
							"hasAdvanceSerach": true,
							"idSeparator": ",",
							"isAutoComplete": 1,
							"isDetail": 0,
							"isMultCheckbox": false,
							"isSingle": false,
							"pageSize": 10,
							"quickSearchName": "",
							"type": "57",
							"viewAttr": 3
						},
						"colSpan": 2,
						"conditionType": "BROWSER",
						"domkey": [
							"relatedshareid"
						],
						"fieldcol": 16,
						"isQuickSearch": false,
						"label": getLabel(106,"对象"),
						"labelcol": 6,
						"viewAttr": 3
					}
				],[
					{
						"colSpan": 2,
						"conditionType": "INPUT_INTERVAL",
						"needDefaultValue":false,
						"domkey": [
							"seclevel",
							"seclevelMax"
						],
						"fieldcol": 16,
						"isQuickSearch": false,
						"label": getLabel(683,"安全级别"),
						"labelcol": 6,
						"value": [
							0,
							''
						],
						"viewAttr": 3
					}
				],[
					{
						"colSpan": 2,
						"conditionType": "SELECT",
						"domkey": [
							"sharelevel"
						],
						"fieldcol": 16,
						"isQuickSearch": false,
						"label": getLabel(385,"权限"),
						"labelcol": 6,
						"options": [
							{
								"key": "1",
								"selected": true,
								"showname": getLabel(33564,"查看")
							}, {
								"key": "2",
								"selected": false,
								"showname": getLabel(93,"编辑")
							}
						],
						"viewAttr": 2
					}
				]
			],
			"5": [[
					{
						"browserConditionParam": {
							"completeParams": {},
							"conditionDataParams": {},
							"dataParams": {},
							"destDataParams": {},
							"hasAddBtn": false,
							"hasAdvanceSerach": true,
							"idSeparator": ",",
							"isAutoComplete": 1,
							"isDetail": 0,
							"isMultCheckbox": false,
							"isSingle": false,
							"pageSize": 10,
							"quickSearchName": "",
							"type": "194",
							"viewAttr": 3
						},
						"colSpan": 2,
						"conditionType": "BROWSER",
						"domkey": [
							"relatedshareid"
						],
						"fieldcol": 16,
						"isQuickSearch": false,
						"label": getLabel(106,"对象"),
						"labelcol": 6,
						"value": 3,
						"viewAttr": 2
					}
				],[
					{
						"colSpan": 2,
						"conditionType": "INPUT_INTERVAL",
						"needDefaultValue":false,
						"domkey": [
							"seclevel",
							"seclevelMax"
						],
						"fieldcol": 16,
						"isQuickSearch": false,
						"label": getLabel(683,"安全级别"),
						"labelcol": 6,
						"value": [
							0,
							''
						],
						"viewAttr": 3
					}
				],[
					{
						"colSpan": 2,
						"conditionType": "SELECT",
						"domkey": [
							"sharelevel"
						],
						"fieldcol": 16,
						"isQuickSearch": false,
						"label": getLabel(385,"权限"),
						"labelcol": 6,
						"options": [
							{
								"key": "1",
								"selected": true,
								"showname": getLabel(33564,"查看")
							}, {
								"key": "2",
								"selected": false,
								"showname": getLabel(93,"编辑")
							}
						],
						"viewAttr": 2
					}
				]
			],
			"1": [[
					{
						"browserConditionParam": {
							"completeParams": {},
							"conditionDataParams": {},
							"dataParams": {},
							"destDataParams": {},
							"hasAddBtn": false,
							"hasAdvanceSerach": true,
							"idSeparator": ",",
							"isAutoComplete": 1,
							"isDetail": 0,
							"isMultCheckbox": false,
							"isSingle": false,
							"pageSize": 10,
							"quickSearchName": "",
							"type": "17",
							"viewAttr": 3
						},
						"colSpan": 2,
						"conditionType": "BROWSER",
						"domkey": [
							"relatedshareid"
						],
						"fieldcol": 16,
						"isQuickSearch": false,
						"label": getLabel(106,"对象"),
						"labelcol": 6,
						"viewAttr": 3
					}
				],[
					{
						"colSpan": 2,
						"conditionType": "SELECT",
						"domkey": [
							"sharelevel"
						],
						"fieldcol": 16,
						"isQuickSearch": false,
						"label": getLabel(385,"权限"),
						"labelcol": 6,
						"options": [
							{
								"key": "1",
								"selected": true,
								"showname": getLabel(33564,"查看")
							}, {
								"key": "2",
								"selected": false,
								"showname": getLabel(93,"编辑")
							}
						],
						"viewAttr": 2
					}
				]
			],
			"11": [[
					{
						"browserConditionParam": {
							"completeParams": {},
							"conditionDataParams": {},
							"dataParams": {},
							"destDataParams": {},
							"hasAddBtn": false,
							"hasAdvanceSerach": true,
							"idSeparator": ",",
							"isAutoComplete": 1,
							"isDetail": 0,
							"isMultCheckbox": false,
							"isSingle": false,
							"pageSize": 10,
							"quickSearchName": "",
							"type": "278",
							"viewAttr": 3
						},
						"colSpan": 2,
						"conditionType": "BROWSER",
						"domkey": [
							"relatedshareid"
						],
						"fieldcol": 16,
						"isQuickSearch": false,
						"label": getLabel(106,"对象"),
						"labelcol": 6,
						"viewAttr": 3
					}
				],[
					{
						"colSpan": 2,
						"conditionType": "SELECT_LINKAGE",
						"domkey": [
							"joblevel"
						],
						"fieldcol": 16,
						"isQuickSearch": false,
						"label": getLabel(28169,"岗位级别"),
						"labelcol": 6,
						"options": [
							{
								"key": "0",
								"selected": true,
								"showname": getLabel(140,"总部")
							}, {
								"key": "2",
								"selected": false,
								"showname": getLabel(19437,"指定分部")
							}, {
								"key": "1",
								"selected": false,
								"showname": getLabel(19438,"指定部门")
							}
						],
						"selectLinkageDatas": {
							"1": {
								"browserConditionParam": {
									"completeParams": {},
									"conditionDataParams": {},
									"dataParams": {},
									"destDataParams": {},
									"hasAddBtn": false,
									"hasAdvanceSerach": true,
									"idSeparator": ",",
									"isAutoComplete": 1,
									"isDetail": 0,
									"isMultCheckbox": false,
									"isSingle": false,
									"pageSize": 10,
									"quickSearchName": "",
									"type": "57",
									"viewAttr": 3
								},
								"colSpan": 2,
								"conditionType": "BROWSER",
								"domkey": [
									"jobtitledepartment"
								],
								"fieldcol": 16,
								"isQuickSearch": false,
								"label": "",
								"labelcol": 6,
								"viewAttr": 3
							},
							"2": {
								"browserConditionParam": {
									"completeParams": {},
									"conditionDataParams": {},
									"dataParams": {},
									"destDataParams": {},
									"hasAddBtn": false,
									"hasAdvanceSerach": true,
									"idSeparator": ",",
									"isAutoComplete": 1,
									"isDetail": 0,
									"isMultCheckbox": false,
									"isSingle": false,
									"pageSize": 10,
									"quickSearchName": "",
									"type": "194",
									"viewAttr": 3
								},
								"colSpan": 2,
								"conditionType": "BROWSER",
								"domkey": [
									"jobtitlesubcompany"
								],
								"fieldcol": 16,
								"isQuickSearch": false,
								"label": "",
								"labelcol": 6,
								"viewAttr": 3
							}
						},
						"viewAttr": 2
					}
				],[
					{
						"colSpan": 2,
						"conditionType": "SELECT",
						"domkey": [
							"sharelevel"
						],
						"fieldcol": 16,
						"isQuickSearch": false,
						"label": getLabel(385,"权限"),
						"labelcol": 6,
						"options": [
							{
								"key": "1",
								"selected": true,
								"showname": getLabel(33564,"查看")
							}, {
								"key": "2",
								"selected": false,
								"showname": getLabel(93,"编辑")
							}
						],
						"viewAttr": 2
					}
				]
			],
			"4": [[
					{
						"colSpan": 2,
						"conditionType": "INPUT_INTERVAL",
						"needDefaultValue":false,
						"domkey": [
							"seclevel",
							"seclevelMax"
						],
						"fieldcol": 16,
						"isQuickSearch": false,
						"label": getLabel(683,"安全级别"),
						"labelcol": 6,
						"value": [
							0,
							''
						],
						"viewAttr": 3
					}
				],[
					{
						"colSpan": 2,
						"conditionType": "SELECT",
						"domkey": [
							"sharelevel"
						],
						"fieldcol": 16,
						"isQuickSearch": false,
						"label": getLabel(385,"权限"),
						"labelcol": 6,
						"options": [
							{
								"key": "1",
								"selected": true,
								"showname": getLabel(33564,"查看")
							}, {
								"key": "2",
								"selected": false,
								"showname": getLabel(93,"编辑")
							}
						],
						"viewAttr": 2
					}
				]
			],
			"3": [[
					{
						"browserConditionParam": {
							"completeParams": {},
							"conditionDataParams": {},
							"dataParams": {},
							"destDataParams": {},
							"hasAddBtn": false,
							"hasAdvanceSerach": true,
							"idSeparator": ",",
							"isAutoComplete": 1,
							"isDetail": 0,
							"isMultCheckbox": false,
							"isSingle": true,
							"pageSize": 10,
							"quickSearchName": "",
							"type": "65",
							"viewAttr": 3
						},
						"colSpan": 2,
						"conditionType": "BROWSER",
						"domkey": [
							"relatedshareid"
						],
						"fieldcol": 16,
						"isQuickSearch": false,
						"label": getLabel(106,"对象"),
						"labelcol": 6,
						"viewAttr": 3
					}, {
						"colSpan": 2,
						"conditionType": "SELECT",
						"domkey": [
							"rolelevel"
						],
						"fieldcol": 16,
						"isQuickSearch": false,
						"label": getLabel(139,"级别"),
						"labelcol": 6,
						"options": [
							{
								"key": "0",
								"selected": true,
								"showname": getLabel(124,"部门")
							}, {
								"key": "1",
								"selected": false,
								"showname": getLabel(141,"分部")
							}, {
								"key": "2",
								"selected": false,
								"showname": getLabel(140,"总部")
							}
						],
						"viewAttr": 2
					}
				],[
					{
						"colSpan": 2,
						"conditionType": "INPUT_INTERVAL",
						"needDefaultValue":false,
						"domkey": [
							"seclevel",
							"seclevelMax"
						],
						"fieldcol": 16,
						"isQuickSearch": false,
						"label": getLabel(683,"安全级别"),
						"labelcol": 6,
						"value": [
							0,
							''
						],
						"viewAttr": 3
					}
				],[
					{
						"colSpan": 2,
						"conditionType": "SELECT",
						"domkey": [
							"sharelevel"
						],
						"fieldcol": 16,
						"isQuickSearch": false,
						"label": getLabel(385,"权限"),
						"labelcol": 6,
						"options": [
							{
								"key": "1",
								"selected": true,
								"showname": getLabel(33564,"查看")
							}, {
								"key": "2",
								"selected": false,
								"showname": getLabel(93,"编辑")
							}
						],
						"viewAttr": 2
					}
				]
			]
		}
	];

    @action
    initDatas=(params={})=>{
        this.loading = true;
        const newParams = {...this.conditiontype,...params};
        Apis.getPrjCondition(newParams).then(data=>{
            this.loading = false;
            this.condition = data.condition;
			this.form && !this.form.isFormInit && this.form.initFormFields(data.condition);			
        }).then(()=>{
		   this.initTreeDatas(params);
		})    
    }
    
    initTreeDatas=(params={})=>{
        Apis.getPrjTypeTreePageList({treetype:'batchshare',...params}).then(data=>{
			this.leftTree =data.treedata;
			this.leftTreeCount = data.treecount;
			this.leftTreeCountType = data.treecountcfg;
			this.selectedTreeKey = data.selectedKeys;
			this.doSearch({prjtype:data.selectedKeys});
		})
     }

    doSearch=(params={})=>{
		this.loading = true;
		 //获取表单的参数值
		if(params.prjtype){
			this.appendFormFields({prjtype:{value:params.prjtype}})
			this.selectedTreeKey = params.prjtype;
        }
		const searchParamsAd = this.form.getFormParams();
		if(searchParamsAd.prjtype){
            this.selectedTreeKey = searchParamsAd.prjtype;
        }
		const newParams = { ...searchParamsAd,...params};
        Apis.getBatchShareList(newParams).then(data=>{
			this.tableStore.getDatas(data.sessionkey,  params.current || 1);
			this.topTabCount = data.tabnum;
			this.dataKey = data.sessionkey;
			this.rightMenu = data.rightMenus;
			this.loading = false;
			if(data.appDetachDisableAll){//禁用所有人选项
				let temp =this.shareCondition[0];
				temp.options.splice(5,1);		
				this.shareCondition[0] = temp ;
			}
        })
	}
	onShowColumn=()=>{
		this.tableStore.setColSetVisible(true);
		this.tableStore.tableColSet(true)
    }
    setSelectedTreeKey=(key) =>{
        this.selectedTreeKey = key;
    }
	@action
	setLeftShow=(bool) =>{
        this.showLeft = bool;
	}
	
	clearStatus=()=>{
        this.showSearchAd = false;
        this.selectedTreeKey = "";
		this.clearFormFields();
		this.resetForm();
        this.condition = [];
        this.resetTable(true);
	}
	
    handleShareDialog=(bool)=>{
        this.visible = bool;
    }
    saveBatchShare = (params = {}) => {
		let { share } = params;
		if (share && share.length > 2) {
			Apis.savePrjBatchShare(params).then((data) => {
				if (data.success) {
					message.success(getLabel(119, "共享") + getLabel(15242, "成功"));
					this.visible = false;
				} else {
					message.error(getLabel(119, "共享") + getLabel(128220, "失败"));
				}
				this.visible = false;
			});
		} else {
			// Modal.warning({
			// 	title: getLabel(15172, "系统提示"),
			// 	content: getLabel(15859, "必要信息不完整！"),
			// });
			message.error(getLabel(15859, "必要信息不完整！"));
		}
	}

}

const prjBatchShareStore = new BatchShareStore();
export default prjBatchShareStore;